package com.love.zywanandroid.customerview

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.zat.mes.andrmes.R
import kotlinx.android.synthetic.main.layout_title.view.*

/**
 * @author zy
 * @date :2019-08-23 13:12
 * @description: 通用titlebar
 */
class TitleBar : LinearLayout {

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attributeSet: AttributeSet?) : this(context, attributeSet, 0)
    constructor(context: Context?, attributeSet: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attributeSet,
        defStyleAttr
    ) {

        initView()
    }

    private fun initView() {
        inflate(context, R.layout.layout_title, this)
    }

    /**
     * 设置title
     */
    fun setTitleText(text: String) {
        tVtitle.text = text
    }

    /**
     * 隐藏返回键
     */
    fun setReturnViewGone() {
        rlReturnTitle.visibility = View.GONE
    }
    /**
     * 显示返回键
     */
    fun setReturnViewVisible() {
        rlReturnTitle.visibility = View.VISIBLE
    }
    /**
     * 隐藏右键
     */
    fun setRightViewGone() {
        rlRight.visibility = View.GONE
    }
    /**
     * 显示右键
     */
    fun setRightViewVisible() {
        rlRight.visibility = View.VISIBLE
    }
    /**
     * 设置标题颜色
     */
    fun setTitleTextColor(colorId: Int) {
        tVtitle.setTextColor(ContextCompat.getColor(context, colorId))
    }
    /**
     * 设置标题背景色
     */
    fun setTitleBackGround(colorId: Int) {
        rlTitle.setBackgroundColor(colorId)
    }


}